﻿using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace NetTao.Analyser
{
    public class AnalyseArticlelist : AnalyseBase
    {
        private List<string> _articleList;

        public List<string> ArticleList
        {
            get { return _articleList ?? (_articleList = new List<string>()); }
        }

        public string GetNovelListUrl()
        {
            return Rule.NovelListUrl.Pattern;
        }

        public void AnalyseUrlList()
        {
            ArticleList.Clear();
            string getNovelKey = Rule.NovelUrl.Pattern;
            string url;
            var matchs = Regex.Matches(Content, Rule.NovelList_GetNovelKey.Pattern, Rule.NovelUrl.Options);
            for (int i = 0; i < matchs.Count; i++)
            {
                Match match = matchs[i];
                url = match.Groups[1].Value;
                if (!string.IsNullOrEmpty(url))
                {
                    ArticleList.Add(getNovelKey.Replace("{NovelKey}", url));
                }
            }
        }
    }
}
